/**
 * 扬尘设备列表videoDeviceList.js
 * 版本号： v1.0.0
 */
$(function () {
    var prId = $("#projectId_").val();
    var onLineStatus = $("#onlineStatus_").val();
    var lastChecked = null;
    $("#dustDevice_dataList").datagrid({
        fit: true,
        fitColumns: true,
        method: "POST",
        rownumbers: true,
        singleSelect: true,
        border: false,
        url: CONTEXT_PATH + '/dustDevData/dustDeviceList.do',
        queryParams: {prId:prId,onLineStatus:onLineStatus},
        idField: 'dpcpId',
        frozenColumns: [[
            {field: 'dpcpId', checkbox: true}
        ]],
        columns: [
            [
                {field: 'deviceId', title: '设备编号', width: 100, align: 'left',fixed:true},
                {field: 'dpcpName', title: '项目检测点名称', width: 150, align: 'left',fixed:true},
                {field: 'principal', title: '负责人', width: 70, align: 'left',fixed:true},
                {field: 'onLineStatus', title: '在线状态', width: 70, align: 'center',fixed:true,
                    formatter:function(val){
                        if (val == 1) return "<span style='color: green; font-weight: bold'>在线</span>";
                        if (val == 2) return "<span style='color: red; font-weight: bold'>离线</span>";
                    }
                },
                {field: 'onlineTime', title: '在线时间', width: 120, align: 'left',fixed:true},
                {field: '_operate', title: '操作', width: 60, align: 'left',
                    formatter:function(val,row,index){
                        // 设备在线情况才能查看实时数据
                        if(row.onLineStatus == 1){
                            return '<a href="#" onclick="deviceDesc('+index+')"><font style="color: #0E89CF">查看</font></a>';
                        }
                    }
                }
            ]
        ],
        onLoadSuccess: function (data) {
            if (data.rows.length > 0) {
                lastChecked = null;
                $("#dustDevice_dataList").datagrid("selectRow", 0);
            }
        },
        onCheck:function(rowIndex, rowData){
            var row = $("#dustDevice_dataList").datagrid("getChecked");
            if(row && rowIndex == lastChecked){
                $('#dustDevice_dataList').datagrid("unselectAll");//取消选中当前所有行
                lastChecked = null;
            }else{
                lastChecked = rowIndex;
            }
        }
    });
});

/**
 * 查看具体设备详细参数
 * @param index
 */
function deviceDesc(index){
    $('#dustDevice_dataList').datagrid('selectRow',index);
    var row = $('#dustDevice_dataList').datagrid('getSelected');
    var devState = row.onLineStatus;
    var devStateText = "";
    if(devState == 1){
        devStateText = "<font color='#61BDB8'>在线</font>";
    }else{
        devStateText = "<font color='red'>离线</font>";
    }
    var html ='<div style="float:left;width:40%;height:180%">' +
                    '<div style="width:97%;height:20%;margin:5px;">' +
                        '<div style="width:32.6%;height:49%;border:#8e9191 1px solid;float:left">' +
                            '<div style="margin:10px">' +
                                '<div style="float:left">' +
                                    '<img src="'+ CONTEXT_PATH +'/html/images/dust/aqi.png" style="width:50px;height:60px">'+
                                '</div>'+
                                '<div style="margin-left:5px;float:left;">' +
                                    '<p id="aqiId" style="font-size: 25px"></p>'+
                                    '<p style="font-size: 17px">AQI</p>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                        '<div style="width:32.6%;height:49%;border:#8e9191 1px solid;float:left">' +
                            '<div style="margin:10px">' +
                                '<div style="float:left">' +
                                    '<img src="'+ CONTEXT_PATH +'/html/images/dust/pm25.png" style="width:50px;height:60px">'+
                                '</div>'+
                                '<div style="margin-left:5px;float:left;">' +
                                    '<p>' +
                                        '<span id="pm25" style="font-size: 25px;"></span>'+
                                        '<span style="font-size: 12px;">ug/m3</span>'+
                                    '</p>'+
                                    '<p style="font-size: 17px">PM2.5</p>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                        '<div style="width:32.6%;height:49%;border:#8e9191 1px solid;float:left">' +
                            '<div style="margin:10px">' +
                                '<div style="float:left">' +
                                    '<img src="'+ CONTEXT_PATH +'/html/images/dust/pm25.png" style="width:50px;height:60px">'+
                                '</div>'+
                                '<div style="margin-left:5px;float:left;">' +
                                    '<p>' +
                                        '<span id="pm10" style="font-size: 25px;"></span>'+
                                        '<span style="font-size: 12px;">ug/m3</span>'+
                                    '</p>'+
                                    '<p style="font-size: 17px">PM10</p>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                        '<div style="width:32.6%;height:49%;border:#8e9191 1px solid;float:left">' +
                            '<div style="margin:10px">' +
                                '<div style="float:left">' +
                                    '<img src="'+ CONTEXT_PATH +'/html/images/dust/windSpeed.png" style="width:50px;height:60px">'+
                                '</div>'+
                                '<div style="margin-left:5px;float:left;">' +
                                    '<p>' +
                                        '<span id="windSpeed" style="font-size: 25px;"></span>'+
                                        '<span style="font-size: 12px;">m/s</span>'+
                                    '</p>'+
                                    '<p style="font-size: 17px">风速</p>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                        '<div style="width:32.6%;height:49%;border:#8e9191 1px solid;float:left">' +
                            '<div style="margin:10px">' +
                                '<div style="float:left">' +
                                    '<img src="'+ CONTEXT_PATH +'/html/images/dust/temperature.png" style="width:50px;height:60px">'+
                                '</div>'+
                                '<div style="margin-left:5px;float:left;">' +
                                    '<p>' +
                                        '<span id="temperature" style="font-size: 25px;"></span>'+
                                        '<span style="font-size: 12px;">℃</span>'+
                                    '</p>'+
                                    '<p style="font-size: 17px">温度</p>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                        '<div style="width:32.6%;height:49%;border:#8e9191 1px solid;float:left">' +
                            '<div style="margin:10px">' +
                                '<div style="float:left">' +
                                    '<img src="'+ CONTEXT_PATH +'/html/images/dust/humidity.png" style="width:50px;height:60px">'+
                                '</div>'+
                                '<div style="margin-left:5px;float:left;">' +
                                    '<p>' +
                                        '<span id="humidity" style="font-size: 25px;"></span>'+
                                        '<span style="font-size: 12px;">%</span>'+
                                    '</p>'+
                                    '<p style="font-size: 17px">湿度</p>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                    '</div>'+
                    '<div style="width:95.8%;height:38.6%;border:#8e9191 1px solid;margin:5px;">' +
                        '<p style="margin:2px">' +
                            '<span style="float:left;font-size:12px">设备编号：</span>'+
                            '<span style="float:left;font-size:15px;color:#61BDB8">'+row.deviceId+'</span>'+
                            '<span style="float:left;font-size:15px;margin-left:5%">状态：</span>'+
                            '<span style="float:left;font-size:15px;">'+devStateText+'</span>'+
                        '</p>'+
                        '<p style="margin-top:6px;clear: both;">' +
                            '<span style="font-size:15px;text-align:center">空气污染指数AQI：</span>'+
                        '</p>'+
                        '<div id="aqiMeter" style="width:270px;height:270px;position:relative;left:20px"></div>'+
                    '</div>'+
                    '<div style="width:95.8%;height:40%;border:#8e9191 1px solid;margin:5px;">' +
                        '<p style="margin:2px;">' +
                            '<span style="font-size:18px;font-weight:bold">国家颗粒物标准</span>'+
                        '</p>'+
                        '<p style="margin:2px;">' +
                            '<span style="font-size:16px;font-weight:bold">根据GB3095-2012标准规定</span>'+
                        '</p>'+
                        '<p style="margin:2px;">' +
                            '<span style="float:left;font-size:14px">年平均最大值70μg/m³</span>'+
                            '<span style="float:right;font-size:14px;">日平均最大值150μg/m³</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#008100">优:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">扬尘值 0-50 μg/m³</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#FFFF00">良:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">扬尘值 51-150 μg/m³</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#FF0000">差:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">扬尘值 > 150 μg/m³</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="font-size:16px;font-weight:bold">根据GB3095-2012标准规定</span>'+
                        '</p>'+
                        '<p style="margin:2px;">' +
                            '<span style="float:left;font-size:14px">年平均最大值35μg/m³</span>'+
                            '<span style="float:right;font-size:14px;">日平均最大值75μg/m³</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#008100">优:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">扬尘值 0-35 μg/m³  </span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#FFFF00">良:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">扬尘值 35-75 μg/m³</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#FF0000">差:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">扬尘值 > 75 μg/m³</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="font-size:16px;font-weight:bold">根据GB12523-2011标准规定</span>'+
                        '</p>'+
                        '<p style="margin:2px;">' +
                            '<span style="float:left;font-size:14px">昼间最大噪声70dB</span>'+
                            '<span style="float:right;font-size:14px;">夜间最大噪声55dB</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#008100">优:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">噪声值 0-40 dB</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#FFFF00">良:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">噪声值 41-70 dB</span>'+
                        '</p>'+
                        '<p style="margin:2px;clear: both">' +
                            '<span style="float: left;font-size:15px;color:#FF0000">差:</span>'+
                            '<span style="float: left;font-size:14px;margin-left:3px">噪声值 > 71 dB</span>'+
                        '</p>'+
                    '</div>'+
            '</div>'+
            '<div style="float:left;width:58.5%;height:180%;border:#8e9191 1px solid;margin:5px;margin-left:0.5%">' +
                '<div style="width:90%;height:32%">' +
                    '<div style="margin-top:5px;text-align: center">' +
                        '<p style="font-size: 17px">AQI指数实时数据</p>'+
                    '</div>'+
                    '<div id="aqiData" style="width:540px;height:280px;position:relative;left:10px">' +
                    '</div>'+
                '</div>'+
                '<div style="width:90%;height:32%">' +
                    '<div style="text-align: center">' +
                        '<p style="font-size: 17px">PM2.5历史数据</p>'+
                    '</div>'+
                    '<div id="pm25Data" style="width:540px;height:280px;position:relative;left:10px">' +
                    '</div>'+
                '</div>'+
                '<div style="width:90%;height:32%">' +
                    '<div style="margin-top:5px;text-align: center">' +
                        '<p style="font-size: 17px">PM10历史数据</p>'+
                    '</div>'+
                    '<div id="pm10Data" style="width:540px;height:280px;position:relative;left:10px">' +
                    '</div>'+
                '</div>'+
            '</div>';

    if(row){
        $('#detailWindow').window({
            title:"实时数据查看",
            width:1000,
            height:500,
            modal:true,
            onBeforeOpen:function(){
                $('#detailWindow').html(html);
                startGetData(row)
            },
            onClose:function(){
                //clearInterval(window.getDataTimer);
            }
        });
        $('#detailWindow').window("center");
    }
}

function startGetData(row){
    //获取当天0点的毫秒数作为开始时间
    var startDate= new Date(new Date().toLocaleDateString());
    var start = startDate.getTime();
    getPm25Data(row,start);
    getPm10Data(row,start);
    getData(row,start);
    var getDataTimer = setInterval(function(){getData(row);}, 10000);
    window.getDataTimer = getDataTimer;
}


function getData(row,start) {
    var nowDate = new Date();
    var minutes = nowDate.getMinutes();
    var seconds = nowDate.getSeconds();
    //为整点时才刷新数据
    if(minutes == 0 && seconds == 0){
        getPm25Data(row,start);
        getPm10Data(row,start);
    }
    var nodataImg = '<img src="'+ CONTEXT_PATH +'/html/images/dust/noData.png" style="width:350px;height:220px">';
    $.ajax({
        url: CONTEXT_PATH + "/apiUtil/doGet.do",
        data: {
            url: "http://store.d.guijianyun.com:8000/devices/"+row.deviceId+"/latest"
        },
        type: "get",
        success: function (data) {

            if (data) {
                var jsonObj = $.parseJSON(data);
                if(!jsonObj.data){
                    document.getElementById("aqiId").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("pm25").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("pm10").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("windSpeed").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("temperature").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("humidity").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("aqiMeter").innerHTML = nodataImg;
                    return;
                }
                var pm25 = jsonObj.data.pm25;
                var pm10 = jsonObj.data.pm10;
                var windSpeed = jsonObj.data.wd;
                var temperature = jsonObj.data.tmp;
                var humidity = jsonObj.data.rh;
                if(pm25){
                    var aqi = calc_aqi(pm25);
                    document.getElementById("aqiId").innerHTML = aqi;
                    document.getElementById("pm25").innerHTML = pm25;
                    getAqiMeter(aqi);
                }else{
                    document.getElementById("aqiId").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("pm25").innerHTML ="<font size='16px'>无数据</font>";
                    document.getElementById("aqiMeter").innerHTML = nodataImg;
                }
                if(pm10){
                    document.getElementById("pm10").innerHTML = pm10;
                }else{
                    document.getElementById("pm10").innerHTML ="<font size='16px'>无数据</font>";
                }
                if(windSpeed){
                    document.getElementById("windSpeed").innerHTML = windSpeed;
                }else{
                    document.getElementById("windSpeed").innerHTML ="<font size='16px'>无数据</font>";
                }
                if(temperature){
                    document.getElementById("temperature").innerHTML = temperature;
                }else{
                    document.getElementById("temperature").innerHTML ="<font size='16px'>无数据</font>";
                }
                if(humidity){
                    document.getElementById("humidity").innerHTML = humidity;
                }else{
                    document.getElementById("humidity").innerHTML ="<font size='16px'>无数据</font>";
                }
            }
        }
    })
}

//aqi优良等级
function getAqiMeter(aqiData){
    var aqiRank = "";
    switch (aqiData) {
        case aqiData <= 50:
            aqiRank = "优";
            break;
        case aqiData <= 100 && aqiData > 50:
            aqiRank = "良";
            break;
        case aqiData <= 150 && aqiData > 100:
            aqiRank = "轻度";
            break;
        case aqiData <= 200 && aqiData > 150:
            aqiRank = "中度";
            break;
        case aqiData <= 300 && aqiData > 200:
            aqiRank = "重度";
            break;
        case aqiData <= 500 && aqiData > 300:
            aqiRank = "严重";
            break;
        default:aqiRank = "无";
    }
    var myChart = echarts.init(document.getElementById('aqiMeter'));
    var option = {
        tooltip: {
            formatter: "{a} <br/>{b} : {c}"
        },
        series: [{
            min: 0,
            max: 500,
            axisLine: {
                width: 20,
                show: true,
                lineStyle: {
                    width: 30,
                    shadowBlur: 0,
                    color: [
                        [0.1, '#3CB371'],
                        [0.2, '#7CFC00'],
                        [0.3, '#ADFF2F'],
                        [0.4, '#FFA500'],
                        [0.6, '#FFFF00'],
                        [1, '#FF0000']
                    ]
                }
            },
            name: 'AQI',
            type: 'gauge',
            axisTick: {
                splitNumber: 30
            },
            //detail: {formatter:'{value}%'},
            detail: {
                formatter: "{value}",
                offsetCenter: [0, "60"],
                textStyle: {
                    fontSize: 25,
                    color: "#5BB1EF"
                }
            },
            data: [{
                value: aqiData,
                name: aqiRank
            }]
        }]
    };
    myChart.setOption(option);
}
//pm2.5历史数据
function getPm25Data(row,start){
    var nodataImg = '<img src="'+ CONTEXT_PATH +'/html/images/dust/noData.png" style="width:350px;height:220px;margin-left: 10%">';
    $.ajax({
        url: CONTEXT_PATH + "/apiUtil/doGet.do",
        data: {
            url: "http://store.d.guijianyun.com:8000/service/calc?start="+start+"&device_id="+row.deviceId+"&resample=H&value=pm25"
        },
        type: "get",
        success: function (data) {
            if (isEmptyObject(data)) {
                var jsonObj = $.parseJSON(data);
                if(jsonObj){
                    var pm25Times = [];
                    var pm25Datas = [];
                    var aqiDatas = [];
                    for(var time in jsonObj){
                        var newTime = new Date(time);
                        var hour = newTime.getHours();
                        var pm25 = jsonObj[time];
                        if(pm25 == null){
                            aqiDatas.push(null)
                        }else{
                            var aqi = calc_aqi(pm25);
                            aqiDatas.push(aqi);
                        }
                        pm25Times.push(hour + "时");
                        pm25Datas.push(jsonObj[time]);
                    }
                    getAqiEchart(pm25Times,aqiDatas);
                    getPm25Echart(pm25Times,pm25Datas);
                }
            }else{
                document.getElementById("aqiData").innerHTML =nodataImg;
                document.getElementById("pm25Data").innerHTML =nodataImg;
            }
        },
        error: function () {
            document.getElementById("aqiData").innerHTML =nodataImg;
            document.getElementById("pm25Data").innerHTML =nodataImg;
        }
    });
}
//构建aqi图形
function getAqiEchart(times,aqiDatas){
    var myChart = echarts.init(document.getElementById('aqiData'));
    var option = {
        xAxis: {
            data: times,
            splitLine: {
                lineStyle: {
                    color: '#D4DFF5'
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#289bd3',
                    width: 2
                }
            },
            axisLabel: {
                textStyle: {
                    fontSize: 14,
                    color: '#333'
                }
            }
        },
        yAxis: {
            axisLine: {
                lineStyle: {
                    color: '#289bd3',
                    width: 2
                }
            },
            axisLabel: {
                textStyle: {
                    fontSize: 14,
                    color: '#333'
                }
            },
            max: 500
        },
        tooltip: {
            trigger: 'axis',
        },
        series: [{
            name:'aqi数据',
            type: 'line',
            smooth: true,
            data: aqiDatas,
            itemStyle: {
                normal:{
                    color: '#2ec7c9',
                }

            },
            lineStyle:{
                width:5
            },
            markPoint: {
                itemStyle: {
                    normal:{
                        color: '#2ec7c9'
                    }

                },
                data: [{
                    type: 'max',
                    name: '最大值'
                }, {
                    type: 'min',
                    name: '最小值'
                }]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }]
    };
    myChart.setOption(option);
}
//构建pm25图形
function getPm25Echart(times,pm25Datas){
    var myChart = echarts.init(document.getElementById('pm25Data'));
    var option = {
        xAxis: {
            data: times,
            splitLine: {
                lineStyle: {
                    color: '#D4DFF5'
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#289bd3',
                    width: 2
                }
            },
            axisLabel: {
                textStyle: {
                    fontSize: 14,
                    color: '#333'
                }
            }
        },
        yAxis: {
            axisLine: {
                lineStyle: {
                    color: '#289bd3',
                    width: 2
                }
            },
            axisLabel: {
                textStyle: {
                    fontSize: 14,
                    color: '#333'
                }
            },
            max: 500
        },
        tooltip: {
            trigger: 'axis'
        },
        series: [{
            type: 'line',
            smooth: true,
            data: pm25Datas,
            itemStyle: {
                normal:{
                    color: '#2ec7c9'
                }

            },
            lineStyle:{
                width:5
            },
            markPoint: {
                itemStyle: {
                    normal:{
                        color: '#2ec7c9'
                    }

                },
                data: [{
                    type: 'max',
                    name: '最大值'
                }, {
                    type: 'min',
                    name: '最小值'
                }]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }]
    };
    myChart.setOption(option);
}
//pm10历史数据
function getPm10Data(row,start){
    var nodataImg = '<img src="'+ CONTEXT_PATH +'/html/images/dust/noData.png" style="width:350px;height:220px;margin-left: 10%">';
    $.ajax({
        url: CONTEXT_PATH + "/apiUtil/doGet.do",
        data: {
            url: "http://store.d.guijianyun.com:8000/service/calc?start=" + start + "&device_id=" + row.deviceId + "&resample=H&value=pm10"
        },
        type: "get",
        success: function (data) {
            if (isEmptyObject(data)) {
                var jsonObj = $.parseJSON(data);
                if (jsonObj) {
                    var pm10Times = [];
                    var pm10Datas = [];
                    for(var time in jsonObj){
                        var newTime = new Date(time);
                        var hour = newTime.getHours();
                        var pm10 = jsonObj[time];
                        pm10Times.push(hour + "时");
                        pm10Datas.push(pm10);
                    }
                    getPm10Echart(pm10Times,pm10Datas);
                }
            }else{
                document.getElementById("pm10Data").innerHTML =nodataImg;
            }
        },
        error: function(){
            document.getElementById("pm10Data").innerHTML =nodataImg;
        }
    })
}
//构建pm10图形
function getPm10Echart(times,pm10Datas){
    var myChart = echarts.init(document.getElementById('pm10Data'));
    var option = {
        xAxis: {
            data: ['01-29', '01-30', '01-31', '02-01', '02-02', '02-03', '02-04'],
            splitLine: {
                lineStyle: {
                    color: '#D4DFF5'
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#289bd3',
                    width: 2
                }
            },
            axisLabel: {
                textStyle: {
                    fontSize: 14,
                    color: '#333'
                }
            }
        },
        yAxis: {
            axisLine: {
                lineStyle: {
                    color: '#289bd3',
                    width: 2
                }
            },
            axisLabel: {
                textStyle: {
                    fontSize: 14,
                    color: '#333'
                }
            },
            max: 500
        },
        tooltip: {
            trigger: 'axis'
        },
        series: [{
            name:'PM2.5数据',
            type: 'line',
            smooth: true,
            data: [120, 182, 191, 234, 450, 430, 310],
            itemStyle: {
                normal:{
                    color: '#2ec7c9'
                }

            },
            lineStyle:{
                width:5
            },
            markPoint: {
                itemStyle: {
                    normal:{
                        color: '#2ec7c9'
                    }

                },
                data: [{
                    type: 'max',
                    name: '最大值'
                }, {
                    type: 'min',
                    name: '最小值'
                }]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }]
    };
    myChart.setOption(option);
}
//aqi计算
function calc_aqi(val){
    var ti = [0, 50, 100, 150, 200, 300, 400, 500]
    var tv = [0, 35, 75, 115, 150, 250, 350, 500]

    var i = 0;

    for (i in tv) {
        if (val < tv[i]) {
            break;
        }
        i = i + 1
        if (i == 7)
            return 600;
    }

    i = val/tv[i]*ti[i];
    return i;
}
//判断对象是否为空
function isEmptyObject(obj) {
    for (var key in obj){
        return false;//返回false，不为空对象
    }
    return true;//返回true，为空对象
}


